package com.suanfa.dp;

import java.util.Scanner;

/**
 * 环形数组最大和
 */
public class CircleArrMaxSum {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String num = in.nextLine();
        int[] arr = new int[Integer.valueOf(num)];

        String str = in.nextLine();  // 读取一行
        String[] strs = str.trim().split(" ");
        for(int i = 0; i< strs.length; i++){
            arr[i] = Integer.valueOf(strs[i]);
        }
        System.out.println(maxSum(arr));
    }

    public static int maxSum(int[] arr){

        int length = arr.length;
        int max = 0;
        int last = 0;
        for(int  i = 0; i< length * 2; i++){
            int index = i% length;
            int value = arr[index];
            max = Math.max(last + value, value);
            last = Math.max(max, last);
        }
        return  last;
    }
}
